Options are | |
---|---|
text | Label of checkbox. |
Bg / fg | set background / foreground color. |
width / height | Horizontal and vertical offset in pixels. |
command | Event Handler function to be call when clicked. |
onvalue | value when selected. Default is 1. |
offvalue | value when not selected. default is 0. |
variable |
|
from tkinter import * from tkinter.messagebox import * class MyFrame(Tk): def __init__(self): super().__init__() self.res=StringVar() self.res.set("married") self.c1=Checkbutton(self,text="Married",onvalue=" married", offvalue="unmarried",variable=self.res) self.c1.pack() self.b1=Button(self,text="Result",command=self. showresult) self.b1.pack() def showresult(self): showinfo(message=self.res.get()) frm=MyFrame() frm.mainloop()
from tkinter import * from tkinter.messagebox import * class MyFrame(Tk): def __init__(self): super().__init__() self.res=StringVar() self.res.set("married") self.c1=Checkbutton(self,text="Married",command=self. showresult,onvalue="married",offvalue="unmarried", variable=self.res) self.c1.pack() def showresult(self): showinfo(message=self.res.get()) frm=MyFrame() frm.mainloop()
from tkinter import * from tkinter.messagebox import * class MyFrame(Tk): def __init__(self): super().__init__() self.la=Label(self,text="Basic Sal:") self.la.grid() self.ta=Entry(self,width=10) self.ta.grid(row=0,column=1,columnspan=2) self.bonus=IntVar() self.c1=Checkbutton(self,text="Add Bonus 5000",onvalue =5000,variable=self.bonus) self.c1.grid(row=1,column=0,columnspan=3,sticky="W") self.hra=IntVar() self.c2=Checkbutton(self,text="Add HRA 3000",onvalue =3000,variable=self.hra) self.c2.grid(row=2,column=0,columnspan=3,sticky="W") self.b1=Button(self,text="Net Salary",command=self.cal) self.b1.grid(row=3,column=1) def cal(self): bs=int(self.ta.get()) ns=bs+self.bonus.get()+self.hra.get() showinfo("Result","Net Sal:"+str(ns)) frm=MyFrame() frm.mainloop()